package com.tax.config.filter;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * LogApiAspect 日志记录
 */
@Aspect
@Component
@Order(1)
public class LogAspect {
    private static Logger logger = LoggerFactory.getLogger(LogAspect.class);


    @Autowired
    private LogService logService;



    @Pointcut(value = "@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        logService.initLogInfo(joinPoint);
    }


    @Pointcut(value = "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)")
    public void webLog() {
    }

    @AfterReturning(returning = "o", pointcut = "pointCut()")
    public void after(Object o) {
        logService.resultLog(o);
    }

    @AfterReturning(returning = "o", pointcut = "webLog()")
    public void after1(Object o) {
        logService.resultLog(o);
    }

}
